<?php
session_start();
include("include/db_connect.php"); 
connect();
$sql="SET CHARACTER SET UTF8";   
query($sql);
$sql = 'select * from tb_report where id = '.$_POST['report_id'].'';
$qr = select($sql);
$rs = $qr[0];

$fileupload=$_FILES['fileField']['tmp_name'];
$fileupload_name=$_FILES['fileField']['name'];
$fileupload_size=$_FILES['fileField']['size'];
$fileupload_type=$_FILES['fileField']['type'];
if($fileupload)
{
	@unlink('../upload/'.$rs['report_doc'].'');
	$insert_id = $_POST['report_id'];
	$array_last=explode(".",$fileupload_name);
	$c=count($array_last)-1; 
	$lastname=strtolower($array_last[$c]) ;
	$filename=date("YmdHis")."_".$insert_id.".".$lastname;
	if(move_uploaded_file($fileupload,"../upload/$filename")){
		$data = array(
			"report_doc"=>$filename
		);
		update("tb_report",$data,"id = '".$insert_id."'");
	}
	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	echo "<script>alert('อัพโหลดกรมธรรม์เรียบร้อยแล้ว');window.location='admin.php?page=report';</script>";
}else{
	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	echo "<script>alert('ท่านยังไม่ได้ระบุไฟล์');window.location='admin.php?page=report';</script>";
}
	
?>